package com.cash.app.manager

import com.cash.app.constant.AppConstant.APP_UPDATE_FORCE
import com.cash.app.constant.AppConstant.APP_UPDATE_OPTIONAL
import com.cash.app.constant.AppConstant.APP_WINDOW_OPEN
import com.cash.app.constant.AppConstant.K_APP_SHOW_UPDATE
import com.cash.app.manager.model.GlobalConfigResponse
import com.cash.app.utils.SpUtils

/**
 * Global configuration data manager
 * Singleton class to store and manage GlobalConfigResponse data
 */
object GlobalConfigManager {

    private var configData: GlobalConfigResponse? = null

    fun updateConfig(config: GlobalConfigResponse?) {
        configData = config
    }

    fun getCountry(): String = configData?.sw_country ?: ""

    fun getSmsType(): Int = configData?.sms_type ?: 0

    fun isHit(): Boolean = configData?.sw_is_hit == 1

    fun getUserNo(): Int = configData?.sw_user_no ?: 0

    fun getUpdateType(): Int = configData?.update_type ?: 0

    fun getAge(): Int = configData?.sw_age ?: 0

    fun isWindowOpen(): Boolean = configData?.window_open == APP_WINDOW_OPEN

    fun getWindowTitle(): String = configData?.window_title ?: ""

    fun getWindowRemark(): String = configData?.window_remark ?: ""

    fun getWindowTimes(): Int = configData?.window_times ?: 0

    fun getEmailAddress(): String = "test123@google.com" // configData?.email_address ?: ""

    fun getWhatsApp1(): String = configData?.wa_1 ?: ""

    fun getWhatsApp2(): String = configData?.wa_2 ?: ""

    fun getLatestVersion(): String = configData?.latest_ver ?: ""

    fun getCompatibleVersion(): String = configData?.comp_ver ?: ""

    fun showContactUs(): Boolean = configData?.show_contactus == 1

    fun isFastApplyEnabled(): Boolean = configData?.fast_apply == 1

    fun getOrderNums(): Int = configData?.sw_order_nums ?: 0

    fun isNeedUpdate(): Boolean {
        return getUpdateType() == APP_UPDATE_FORCE || (getUpdateType() == APP_UPDATE_OPTIONAL && SpUtils.get(
            K_APP_SHOW_UPDATE, true
        ))
    }

    fun getSmsKeyword(): List<String> {
        return configData?.sms_words ?: emptyList()
    }

    fun clear() {
        configData = null
    }
} 